package com.estar.integaration.Reader.Listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.estar.integaration.Util.Util;
import com.estar.integaration.entity.paymentPlanEntity.SupplierAccountPeriod;
import lombok.AllArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: YJL
 * Date: 2022/2/17 16:45
 **/
@AllArgsConstructor
public class SupplierAccountPeriodListener extends AnalysisEventListener<SupplierAccountPeriod> {

  List<SupplierAccountPeriod> supplierAccountPeriodList = new ArrayList<>();

  @Override
  public void invoke(SupplierAccountPeriod supplierAccountPeriod, AnalysisContext analysisContext) {
    //不为空时添加进去
    if(supplierAccountPeriod.getSupplierName() != null){
      supplierAccountPeriod.setId(Util.getUUID());
      if( supplierAccountPeriod.getRealNeedAddDay() == null || supplierAccountPeriod.getRealNeedAddDay().equals("")
      || supplierAccountPeriod.getRealNeedAddDay().equals(" ")
      || supplierAccountPeriod.getNaturalSentence() != null
      ){
        supplierAccountPeriod.setRealNeedAddDay("-1");//-1的时候就是需要写入的
      }
      supplierAccountPeriodList.add(supplierAccountPeriod);
    }
  }

  @Override
  public void doAfterAllAnalysed(AnalysisContext analysisContext) {

  }
}
